package com.har.modules.web.controller;


import com.har.common.exception.RRException;
import com.har.common.utils.PageUtils;
import com.har.common.utils.Query;
import com.har.common.utils.R;
import com.har.modules.web.entity.BaseProducEntity;
import com.har.modules.web.entity.FinancEntity;
import com.har.modules.web.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 *
 * 企业金融政策
 *
 * @author maorui
 *
 */

@RestController
@RequestMapping("/financia")
public class FinancialController {

    @Autowired
    private BaseProducService baseProducService;

    @Autowired
    private FinancialService financialService;

    @Autowired
    private FinancService financService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) throws Exception{
        PageUtils page=financialService.queryPage(params);
        Query<FinancEntity> query=new Query(params);
        //查询总条数
        int total = financialService.queryTotal(query);
        if(page.getList().isEmpty()){
            throw new RRException("暂无数据，或者请输入合适的分页参数");
        }
        PageUtils pageUtil = new PageUtils(page.getList(), total, query.getLimit(), page.getCurrPage());

        BaseProducEntity baseProducEntity=baseProducService.selectByType(5);

        return R.ok().put("data", pageUtil).put("type",baseProducEntity.getType());
    }


    /**
     *
     *   企业金融政策详细信息
     * @param id
     * @return
     */

    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        FinancEntity financEntity=financService.selectById(id);
        if (null==financEntity) {
            throw new RRException("查询出错");
        }
        return R.ok().put("data", financEntity);
    }
}
